using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;

using Gizmox.WebGUI.Forms;
using Gizmox.WebGUI.Common.Resources;
using Gizmox.WebGUI.Common.Interfaces;
using System.IO;
using BUS;
using DTO;
using TVC.Modules.Ddb;

namespace TVC
{

    /// <summary>
    /// Summary description for BaseForm.
    /// </summary>
    [Serializable()]
    public class BaseForm : Form
    {
        protected DTO.PODInfo _podInfo = new DTO.PODInfo();

        protected string _db = "TVC";

        public string DB
        {
            get { return _db; }
            set { _db = value; }
        }

        public DTO.PODInfo PODInfo
        {
            get { return _podInfo; }
            set { _podInfo = value; }
        }
        protected string _language = "eng";
        private RootCategoryNode mobjRootCategoryNode = null;
        private Gizmox.WebGUI.Forms.Splitter mobjSplitterVert;

        private Gizmox.WebGUI.Forms.NavigationTabs mobjTabsMain;

        public Gizmox.WebGUI.Forms.NavigationTabs TabsMain
        {
            get { return mobjTabsMain; }
            set { mobjTabsMain = value; }
        }



     //   protected Gizmox.WebGUI.Forms.ToolBar mobjToolBarMain;

        private Gizmox.WebGUI.Forms.Panel mobjPanelSpace;
        private Gizmox.WebGUI.Forms.Panel mobjPoweredByPanel;
        private Gizmox.WebGUI.Forms.MainMenu mobjMainMenu;
        private Gizmox.WebGUI.Forms.MenuItem mobjChangePWD;
        private Gizmox.WebGUI.Forms.MenuItem mobjTheme;
        private Gizmox.WebGUI.Forms.MenuItem mobjMenuAboutVWG;
        private Gizmox.WebGUI.Forms.MenuItem mobjThemesMenu;

     //   private IHostedApplication mobjCurrentHostedApplication = null;

        protected WorkspaceTabs _mobjTabWorkSpace = null;
      //  private Control mobjCurrentHostedControl = null;
        private Gizmox.WebGUI.Forms.Panel mobjPanelCategories;

        private Gizmox.WebGUI.Forms.Extenders.UniqueIdExtender objUniqueId = new Gizmox.WebGUI.Forms.Extenders.UniqueIdExtender();
        protected SearchTextBox mobjCommandText;
        private Splitter splitter1;
        private MenuItem mobjDDB;
        private MenuItem mobjLogout;
        private Panel panel1;
        private StatusBar mobjStatusBar;
        private StatusBarPanel sbpErr;
        private StatusBarPanel sbpLogon;
        private PictureBox Next;
        private PictureBox Back;
        string sErr = "";
        private NavigationTabs navigationTabs1;
        private Button btnEsc;

        /// <summary> 
        /// Required designer variable.
        /// </summary>
        [NonSerialized]
        private System.ComponentModel.Container components = null;

        public BaseForm()
        {
            // This call is required by the WebGUI Form Designer.
            InitializeComponent();
            //this.mobjCommandText.Location = new System.Drawing.Point(350, 5);
            //mobjCommandText.BringToFront();

            // Initialize the workspace area
            InitializeWorkspace();

            this.mobjMainMenu.MenuClick += new MenuEventHandler(mobjMainMenu_MenuClick);
            //this.mobjPictureBoxPoweredBy.Image = new ImageResourceHandle("PoweredByLogo.png");
            //this.pbLogo.Click += new EventHandler(mobjPictureBoxPoweredBy_Click);
            //this.pbLogo.Cursor = Cursors.Hand;


            //objUniqueId.SetUniqueId(mobjPictureBoxPoweredBy, "test1111");

            // Attach the selected-index-changed event
            this.mobjTabsMain.SelectedIndexChanged += new EventHandler(mobjTabsMain_SelectedIndexChanged);
            objUniqueId.SetUniqueId(mobjTabsMain, "fttt");
            Application.ThreadBookmarkNavigate += new ThreadBookmarkEventHandler(Application_ThreadBookmarkNavigate);

        }

        void mobjCommandText_Search(object sender, EventArgs e)
        {
            SelectCategory(mobjCommandText.Text, "");

            //mobjRootCategoryNode.Nodes.s
            //mobjRootCategoryNode.AddCategory(

        }


        void mobjPictureBoxPoweredBy_Click(object sender, EventArgs e)
        {
            Link.Open("http://www.tavicosoft.com");
        }

        private void InitalizeThemeMenu()
        {
            mobjThemesMenu = new MenuItem("Themes");

            foreach (string strTheme in VWGContext.Current.Config.Themes)
            {
                MenuItem objThemeMenu = new MenuItem(strTheme);
                objThemeMenu.Tag = string.Format("Theme.{0}", strTheme);
                mobjThemesMenu.MenuItems.Add(objThemeMenu);
            }

            mobjTheme.MenuItems.Add(mobjThemesMenu);

            UpdateThemeMenu();
        }

        private void UpdateThemeMenu()
        {
            foreach (MenuItem objMenuItem in mobjTheme.MenuItems)
            {
                objMenuItem.RadioCheck = ((string)objMenuItem.Tag == VWGContext.Current.CurrentTheme);
            }
        }

        /// <summary>
        /// Handles navigation tabs selection of item by navigating to the selected
        /// category within this navigation category item
        /// </summary>
        /// <param name="sender">The sender object</param>
        /// <param name="e">Event arguments</param>
        void mobjTabsMain_SelectedIndexChanged(object sender, EventArgs e)
        {

            // Check that there is a selected item
            if (mobjTabsMain.SelectedItem != null)
            {

                //// add control PictureBox 
                //if (mobjTabsMain.SelectedItem.Text == "Home")
                //{
                //    //GetMainForm().PODInfo.EMP_ID 
                //    // Load the picture into a PictureBox.
                //    LoadImage();

                //}
                //else
                //{
                //    picAvatar.Visible = false;
                //}

                // Check that there are controls contained in this nav-tab
                if (mobjTabsMain.SelectedItem.Controls.Count > 0)
                {
                    // Get the selected category tree-node from within the nav-tab 
                    // treeview control and navigate to the selected control
                    // if there is any.
                    TreeView objTreeView = mobjTabsMain.SelectedItem.Controls[0] as TreeView;
                    if (objTreeView != null && objTreeView.SelectedNode != null)
                    {
                        CategoryNode node = objTreeView.SelectedNode.Tag as CategoryNode;
                        this.SelectCategory(node, node.Command, true);
                    }
                }
            }
        }

        protected virtual void LoadImage()
        {
            //string _pathImage = MainForm.ServerPath + "Resources\\Images\\";
            //UsersControl Emp = new UsersControl();
            //UsersInfo Empinfo = Emp.Get(DB, PODInfo.EMP_ID, ref sErr);

            // // Directory.GetFiles(_pathImage + );
            //ImageResourceHandle imageName = new ImageResourceHandle();
            //if (Empinfo.PhotoPath == "")
            //{
            //    imageName.File = "noavatar.jpg";
            //    this.picAvatar.Image = imageName;
            //}
            //else
            //{
            //    string[] file = System.IO.Directory.GetFiles(_pathImage, "*" + Empinfo.PhotoPath);
            //    if (file != null & file.Length == 1)
            //    {

            //        imageName.File = Path.GetFileName(file[0]);// Empinfo.PhotoPath;//+ ".jpg"MainForm.ServerPath+"Resource"+
            //    }
            //    else
            //    {
            //        imageName.File = "noavatar.jpg";
            //        this.picAvatar.Image = imageName;
            //    }

            //    if (imageName.IsServerResource)
            //        this.picAvatar.Image = imageName;

            //}

            //picAvatar.Visible = true;
            //picAvatar.SizeMode = PictureBoxSizeMode.StretchImage;

            //this.picAvatar.BringToFront();

        }

        void Application_ThreadBookmarkNavigate(object sender, ThreadBookmarkEventArgs e)
        {
            if (this.Context.MainForm == this)
            {
                SelectCategory((CategoryNode)e.Data, "", false);
            }
        }

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        protected virtual void InitializeWorkspace() { }
        protected virtual void SetTitle(string title) { }

        #region Form Designer generated code

        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(BaseForm));
            this.mobjTabsMain = new Gizmox.WebGUI.Forms.NavigationTabs();
            this.mobjSplitterVert = new Gizmox.WebGUI.Forms.Splitter();
         //   this.mobjToolBarMain = new Gizmox.WebGUI.Forms.ToolBar();
            this.mobjPanelSpace = new Gizmox.WebGUI.Forms.Panel();
            this.mobjPoweredByPanel = new Gizmox.WebGUI.Forms.Panel();
            this.mobjMainMenu = new Gizmox.WebGUI.Forms.MainMenu();
            this.mobjDDB = new Gizmox.WebGUI.Forms.MenuItem();
            this.mobjTheme = new Gizmox.WebGUI.Forms.MenuItem();
            this.mobjChangePWD = new Gizmox.WebGUI.Forms.MenuItem();
            this.mobjLogout = new Gizmox.WebGUI.Forms.MenuItem();
            this.mobjMenuAboutVWG = new Gizmox.WebGUI.Forms.MenuItem();
            this.mobjPanelCategories = new Gizmox.WebGUI.Forms.Panel();
            this.mobjCommandText = new Gizmox.WebGUI.Forms.SearchTextBox();
            this.splitter1 = new Gizmox.WebGUI.Forms.Splitter();
            this.panel1 = new Gizmox.WebGUI.Forms.Panel();
            this.Back = new Gizmox.WebGUI.Forms.PictureBox();
            this.Next = new Gizmox.WebGUI.Forms.PictureBox();
            this.mobjStatusBar = new Gizmox.WebGUI.Forms.StatusBar();
            this.sbpErr = new Gizmox.WebGUI.Forms.StatusBarPanel();
            this.sbpLogon = new Gizmox.WebGUI.Forms.StatusBarPanel();
            this.navigationTabs1 = new Gizmox.WebGUI.Forms.NavigationTabs();
            this.btnEsc = new Gizmox.WebGUI.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.mobjTabsMain)).BeginInit();
            this.mobjPanelCategories.SuspendLayout();
            this.panel1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.Back)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.Next)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.sbpErr)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.sbpLogon)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.navigationTabs1)).BeginInit();
            this.SuspendLayout();
            // 
            // mobjTabsMain
            // 
            this.mobjTabsMain.BackgroundImageLayout = Gizmox.WebGUI.Forms.ImageLayout.None;
            this.mobjTabsMain.CustomStyle = "Navigation";
            this.mobjTabsMain.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.mobjTabsMain.Location = new System.Drawing.Point(0, 0);
            this.mobjTabsMain.Name = "mobjTabsMain";
            this.mobjTabsMain.Size = new System.Drawing.Size(163, 575);
            this.mobjTabsMain.TabIndex = 0;
            // 
            // mobjSplitterVert
            // 
            this.mobjSplitterVert.BackgroundImageLayout = Gizmox.WebGUI.Forms.ImageLayout.None;
            this.mobjSplitterVert.Location = new System.Drawing.Point(166, 3);
            this.mobjSplitterVert.Name = "mobjSplitterVert";
            this.mobjSplitterVert.Size = new System.Drawing.Size(2, 645);
            this.mobjSplitterVert.TabIndex = 1;
            this.mobjSplitterVert.TabStop = false;
            // 
            // mobjToolBarMain
            // 
            //this.mobjToolBarMain.Appearance = Gizmox.WebGUI.Forms.ToolBarAppearance.Normal;
            //this.mobjToolBarMain.BackgroundImageLayout = Gizmox.WebGUI.Forms.ImageLayout.None;
            //this.mobjToolBarMain.DragHandle = true;
            //this.mobjToolBarMain.DropDownArrows = true;
            //this.mobjToolBarMain.ImageSize = new System.Drawing.Size(16, 16);
            //this.mobjToolBarMain.Location = new System.Drawing.Point(3, 3);
            //this.mobjToolBarMain.MenuHandle = true;
            //this.mobjToolBarMain.Name = "mobjToolBarMain";
            //this.mobjToolBarMain.ShowToolTips = true;
            //this.mobjToolBarMain.Size = new System.Drawing.Size(100, 22);
            //this.mobjToolBarMain.TabIndex = 3;
            // 
            // mobjPanelSpace
            // 
            this.mobjPanelSpace.BackgroundImageLayout = Gizmox.WebGUI.Forms.ImageLayout.None;
            this.mobjPanelSpace.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.mobjPanelSpace.Location = new System.Drawing.Point(176, 3);
            this.mobjPanelSpace.Name = "mobjPanelSpace";
            this.mobjPanelSpace.Size = new System.Drawing.Size(544, 645);
            this.mobjPanelSpace.TabIndex = 4;
            // 
            // mobjPoweredByPanel
            // 
            this.mobjPoweredByPanel.BackgroundImage = new Gizmox.WebGUI.Common.Resources.ImageResourceHandle(resources.GetString("mobjPoweredByPanel.BackgroundImage"));
            this.mobjPoweredByPanel.Dock = Gizmox.WebGUI.Forms.DockStyle.Bottom;
            this.mobjPoweredByPanel.Location = new System.Drawing.Point(0, 572);
            this.mobjPoweredByPanel.Name = "mobjPanelSpace";
            this.mobjPoweredByPanel.Size = new System.Drawing.Size(163, 70);
            this.mobjPoweredByPanel.TabIndex = 1;
            this.mobjPoweredByPanel.Click += new System.EventHandler(this.mobjPictureBoxPoweredBy_Click);
            // 
            // mobjMainMenu
            // 
            this.mobjMainMenu.Dock = Gizmox.WebGUI.Forms.DockStyle.Top;
            this.mobjMainMenu.Location = new System.Drawing.Point(0, 0);
            this.mobjMainMenu.MenuItems.AddRange(new Gizmox.WebGUI.Forms.MenuItem[] {
            this.mobjDDB,
            this.mobjTheme,
            this.mobjChangePWD,
            this.mobjLogout,
            this.mobjMenuAboutVWG});
            this.mobjMainMenu.Name = "mobjMainMenu";
            this.mobjMainMenu.Size = new System.Drawing.Size(100, 100);
            // 
            // mobjDDB
            // 
            this.mobjDDB.Index = 0;
            this.mobjDDB.Tag = "DDB";
            this.mobjDDB.Text = "Home";
            // 
            // mobjTheme
            // 
            this.mobjTheme.Index = 1;
            this.mobjTheme.Text = "Themes";
            // 
            // mobjChangePWD
            // 
            this.mobjChangePWD.Index = 2;
            this.mobjChangePWD.Tag = "PWD";
            this.mobjChangePWD.Text = "Change Password";
            // 
            // mobjLogout
            // 
            this.mobjLogout.Index = 3;
            this.mobjLogout.Tag = "LOGOUT";
            this.mobjLogout.Text = "Logout";
            // 
            // mobjMenuAboutVWG
            // 
            this.mobjMenuAboutVWG.Index = 4;
            this.mobjMenuAboutVWG.Tag = "AboutVWG";
            this.mobjMenuAboutVWG.Text = "About";
            // 
            // mobjPanelCategories
            // 
            this.mobjPanelCategories.Controls.Add(this.mobjTabsMain);
            this.mobjPanelCategories.Controls.Add(this.mobjPoweredByPanel);
            this.mobjPanelCategories.Dock = Gizmox.WebGUI.Forms.DockStyle.Left;
            this.mobjPanelCategories.Location = new System.Drawing.Point(3, 6);
            this.mobjPanelCategories.Name = "mobjPanelCategories";
            this.mobjPanelCategories.Size = new System.Drawing.Size(163, 645);
            this.mobjPanelCategories.TabIndex = 5;
            // 
            // mobjCommandText
            // 
            this.mobjCommandText.AllowDrag = false;
            this.mobjCommandText.CustomStyle = "STB";
            this.mobjCommandText.Location = new System.Drawing.Point(3, 6);
            this.mobjCommandText.Name = "mobjCommandText";
            this.mobjCommandText.ScrollBars = Gizmox.WebGUI.Forms.ScrollBars.Both;
            this.mobjCommandText.Size = new System.Drawing.Size(267, 20);
            this.mobjCommandText.TabIndex = 0;
            this.mobjCommandText.WatermarkText = "Command....";
            this.mobjCommandText.Search += new System.EventHandler(this.mobjCommandText_Search);
            // 
            // splitter1
            // 
            this.splitter1.Dock = Gizmox.WebGUI.Forms.DockStyle.Right;
            this.splitter1.Location = new System.Drawing.Point(720, 3);
            this.splitter1.Name = "splitter1";
            this.splitter1.Size = new System.Drawing.Size(3, 667);
            this.splitter1.TabIndex = 7;
            this.splitter1.TabStop = false;
            // 
            // panel1
            // 
            this.panel1.Controls.Add(this.Back);
            this.panel1.Controls.Add(this.Next);
            this.panel1.Controls.Add(this.mobjStatusBar);
            this.panel1.Dock = Gizmox.WebGUI.Forms.DockStyle.Bottom;
            this.panel1.Location = new System.Drawing.Point(243, 573);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(240, 25);
            this.panel1.TabIndex = 8;
            // 
            // Back
            // 
            this.Back.BackgroundImage = new Gizmox.WebGUI.Common.Resources.IconResourceHandle(resources.GetString("Back.BackgroundImage"));
            this.Back.BackgroundImageLayout = Gizmox.WebGUI.Forms.ImageLayout.Stretch;
            this.Back.Dock = Gizmox.WebGUI.Forms.DockStyle.Right;
            this.Back.Location = new System.Drawing.Point(688, 0);
            this.Back.Name = "Back";
            this.Back.Size = new System.Drawing.Size(25, 25);
            this.Back.TabIndex = 7;
            this.Back.TabStop = false;
            this.Back.Visible = false;
            this.Back.Click += new System.EventHandler(this.Back_Click);
            // 
            // Next
            // 
            this.Next.BackgroundImage = new Gizmox.WebGUI.Common.Resources.IconResourceHandle(resources.GetString("Next.BackgroundImage"));
            this.Next.BackgroundImageLayout = Gizmox.WebGUI.Forms.ImageLayout.Stretch;
            this.Next.Dock = Gizmox.WebGUI.Forms.DockStyle.Right;
            this.Next.Location = new System.Drawing.Point(704, 0);
            this.Next.Name = "Next";
            this.Next.Size = new System.Drawing.Size(25, 25);
            this.Next.TabIndex = 7;
            this.Next.TabStop = false;
            this.Next.Click += new System.EventHandler(this.Next_Click);
            // 
            // mobjStatusBar
            // 
            this.mobjStatusBar.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.mobjStatusBar.Location = new System.Drawing.Point(0, 0);
            this.mobjStatusBar.Name = "mobjStatusBar";
            this.mobjStatusBar.Panels.AddRange(new Gizmox.WebGUI.Forms.StatusBarPanel[] {
            this.sbpErr,
            this.sbpLogon});
            this.mobjStatusBar.ShowPanels = true;
            this.mobjStatusBar.Size = new System.Drawing.Size(720, 25);
            this.mobjStatusBar.TabIndex = 6;
            this.mobjStatusBar.Text = "...";
            this.mobjStatusBar.Click += new System.EventHandler(this.mobjStatusBar_Click);
            // 
            // sbpErr
            // 
            this.sbpErr.AutoSize = Gizmox.WebGUI.Forms.StatusBarPanelAutoSize.Spring;
            this.sbpErr.Text = "...";
            this.sbpErr.Width = 500;
            // 
            // sbpLogon
            // 
            this.sbpLogon.Text = "Logon";
            this.sbpLogon.Width = 500;
            // 
            // navigationTabs1
            // 
            this.navigationTabs1.BackgroundImageLayout = Gizmox.WebGUI.Forms.ImageLayout.None;
            this.navigationTabs1.CustomStyle = "Navigation";
            this.navigationTabs1.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.navigationTabs1.Location = new System.Drawing.Point(0, 0);
            this.navigationTabs1.Name = "navigationTabs1";
            this.navigationTabs1.Size = new System.Drawing.Size(237, 667);
            this.navigationTabs1.TabIndex = 0;
            // 
            // btnEsc
            // 
            this.btnEsc.Location = new System.Drawing.Point(598, 650);
            this.btnEsc.Name = "btnEsc";
            this.btnEsc.Size = new System.Drawing.Size(75, 23);
            this.btnEsc.TabIndex = 0;
            this.btnEsc.Text = "Esc";
            this.btnEsc.Visible = false;
            this.btnEsc.Click += new System.EventHandler(this.btnEsc_Click);
            // 
            // BaseForm
            // 
            this.CancelButton = this.btnEsc;
            this.Controls.Add(this.btnEsc);
            this.Controls.Add(this.mobjPanelSpace);
            this.Controls.Add(this.splitter1);
            this.Controls.Add(this.mobjSplitterVert);
            this.Controls.Add(this.mobjPanelCategories);
            this.Controls.Add(this.panel1);
            this.DockPadding.All = 3;
            this.FormBorderStyle = Gizmox.WebGUI.Forms.FormBorderStyle.Sizable;
            this.FormStyle = Gizmox.WebGUI.Forms.FormStyle.Application;
            this.Location = new System.Drawing.Point(0, -256);
            this.Menu = this.mobjMainMenu;
            this.Padding = new Gizmox.WebGUI.Forms.Padding(3);
            this.Size = new System.Drawing.Size(726, 677);
            this.Text = "TAVICO FINANCE & INVENTORY CONTROL SYSTEM";
            this.Load += new System.EventHandler(this.BaseForm_Load);
            ((System.ComponentModel.ISupportInitialize)(this.mobjTabsMain)).EndInit();
            this.mobjPanelCategories.ResumeLayout(false);
            this.panel1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.Back)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.Next)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.sbpErr)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.sbpLogon)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.navigationTabs1)).EndInit();
            this.ResumeLayout(false);

        }

        void BaseForm_Load(object sender, EventArgs e)
        {
            _language = Context.Session["Language"] != null ? Context.Session["Language"].ToString() : "eng";
            InitalizeThemeMenu();
            Next.Visible = false;
            //Back.Visible = true;
            //mobjPanelRightSide.Visible = Next.Visible;
            //this.mobjPanelRightSide.Size = new System.Drawing.Size(1, 622);
            Back.BringToFront();
            Next.BringToFront();
            //this.picAvatar.BringToFront();

        }
        protected virtual void LoadLanguage(string language)
        {
            mobjDDB.Text = clsConfigurarion.GetLabel("TVC", "mobjDDB", mobjDDB.Text, language);
            mobjLogout.Text = clsConfigurarion.GetLabel("TVC", "mobjLogout", mobjLogout.Text, language);
            mobjChangePWD.Text = clsConfigurarion.GetLabel("TVC", "mobjChangePWD", mobjChangePWD.Text, language);
            mobjTheme.Text = clsConfigurarion.GetLabel("TVC", "mobjTheme", mobjTheme.Text, language);
            //clsConfigurarion.GetLabel(this.ToString(), lblDescription, language);
            //clsConfigurarion.GetLabel(this.ToString(), lblLanguage, language);
            //clsConfigurarion.GetLabel(this.ToString(), lblDbDefault, language);
            //clsConfigurarion.GetLabel(this.ToString(), lklRole, language);
            //clsConfigurarion.GetLabel(this.ToString(), lklEmp, language);
        }
        protected virtual void AllowEditLanguage()
        {
            ContextMenu menu = new ContextMenu();
            menu.MenuItems.Add(new MenuItem("Edit Selected Tab Language"));
            mobjPanelCategories.ContextMenu = menu;
            mobjPanelCategories.MenuClick += mobjPanelCategories_MenuClick;
        }

        void mobjPanelCategories_MenuClick(object objSource, MenuItemEventArgs objArgs)
        {
            if (objArgs.Source is NavigationTabs)
            {
                frmInputData frm = new frmInputData();
                frm.Default = ((NavigationTabs)objArgs.Source).SelectedTab.Text;
                frm.FormClosed += (form, args) =>
                {
                    if (((Form)form).DialogResult == DialogResult.OK)
                    {
                        ((NavigationTabs)objArgs.Source).SelectedTab.Text = frm.valuereturn;
                        ((NavigationTabs)objArgs.Source).SelectedTab.Update();
                        clsConfigurarion.SetLabel(((NavigationTabs)objArgs.Source).SelectedTab.Name, "", ((NavigationTabs)objArgs.Source).SelectedTab.Text, _language);
                    }
                };
                frm.ShowDialog();
            }
        }
        protected virtual void UpdateControlLanguage(object obj)
        {
            if (obj is Control)
            {
                Control control = obj as Control;

                frmInputData frm = new frmInputData();
                frm.Default = control.Text;
                frm.FormClosed += (form, args) =>
                {
                    if (((Form)form).DialogResult == DialogResult.OK)
                    {
                        control.Text = frm.valuereturn;
                        clsConfigurarion.SetLabel(this.ToString(), control, _language);
                    }
                };
                frm.ShowDialog();
            }

        }


        #endregion

        protected virtual void ClearWorspace()
        {
        }

        protected virtual void AddWorspaceControl(Control objControl, ToolBar toolbar = null)
        {
        }

        private void SetThreadBookmark(CategoryNode objCategoryNode)
        {
            if (this.Context.MainForm == this)
            {
                Application.SetThreadBookmark(objCategoryNode, objCategoryNode.Text);
            }
        }

        public void SelectCategory(string moduleName, string args,string text = null)
        {
            if (mobjTabsMain.TabPages.Count > 0)
            {
                string strmodule = moduleName;
                // Get the selected category tree-node from within the nav-tab 
                // treeview control and navigate to the selected control
                // if there is any.
                for (int i = 0; i < mobjTabsMain.TabPages.Count; i++)
                {
                    TreeView objTreeView = mobjTabsMain.TabPages[i].Controls[0] as TreeView;
                    if (objTreeView != null)
                    {


                        TreeNode[] arrNodes = objTreeView.Nodes.Find(moduleName, true);
                        if (arrNodes != null && arrNodes.Length > 0)
                        {
                            //objTreeView.SelectedNode = arrNodes[0];
                            //mobjTabsMain.SelectedTab = mobjTabsMain.TabPages[i];
                            CategoryNode node = arrNodes[0].Tag as CategoryNode;
                            if (text != null) node.Text = text;
                            this.SelectCategory(node, args, true);
                            break;
                        }


                    }
                }
            }
        }
        protected TreeNode GetSelectedNode()
        {
            TreeView tree = mobjTabsMain.SelectedTab.Controls[0] as TreeView;
            if (tree == null && mobjTabsMain.SelectedTab.Controls.Count == 2)
                tree = mobjTabsMain.SelectedTab.Controls[1] as TreeView;
            return tree.SelectedNode;
        }
        public void SelectCategory(CategoryNode objCategoryNode, string args, bool blnBookmark)
        {
            if (blnBookmark && objCategoryNode != null)
            {
                SetThreadBookmark(objCategoryNode);
            }

           

            //if (!this.IsMdiContainer && mobjCurrentHostedControl != null)
            //{
            //    mobjCurrentHostedControl.Dispose();
            //}
            if (objCategoryNode != null)
            {
                Control objControl;
                objControl = objCategoryNode.GetCategoryInstance(this as MainForm);
                if (objControl != null)
                {
                    ClearWorspace();
                    objControl.Text = objCategoryNode.Text;
                    ToolBar curToolBar = new ToolBar();
                    //this.mobjToolBarMain = curToolBar;
                    if (objControl != null)
                    {
                        objControl.Dock = DockStyle.Fill;

                        AddWorspaceControl(objControl, curToolBar);

                        IHostedApplication objHostedApplication = objControl as IHostedApplication;

                        if (objHostedApplication != null)
                        {


                            CatalogSettings.InitializeCatalogModule(objHostedApplication, curToolBar, (sender, e) =>
                            {
                                CatalogSettings.HandleApplicationHostToolBarClick(objHostedApplication, curToolBar, (ToolBarButton)sender, e);
                            });//new EventHandler(objToolBarButton_Click)

                            if (objHostedApplication.GetTitle() == null || objHostedApplication.GetTitle() == "")
                                SetTitle(objCategoryNode.Text + " - " + PODInfo.Business_Name);
                            else SetTitle(objHostedApplication.GetTitle());
                            if (args != null && args != "") objHostedApplication.SetObject(args);
                            else objHostedApplication.SetObject(objCategoryNode.Command);


                        }
                        else
                        {
                            SetTitle(objCategoryNode.Text);
                            //if (this.mobjToolBarMain.Buttons.Count > 0)
                            //{
                            //    this.mobjToolBarMain.Buttons.Clear();
                            //    this.mobjToolBarMain.Update();
                            //}
                        }

                        // AddWorspaceControl(objControl);

                        //mobjCurrentHostedControl = objControl;
                        //mobjCurrentHostedApplication = objHostedApplication;
                    }
                    else
                    {
                        //this.mobjToolBarMain.Buttons.Clear();
                    }
                }
            }
        }

        protected RootCategoryNode RootCategory
        {
            get
            {
                if (mobjRootCategoryNode == null)
                {
                    mobjRootCategoryNode = new RootCategoryNode(this.mobjTabsMain, this, "TVC", "44");
                }
                return mobjRootCategoryNode;
            }
        }

        private void objToolBarButton_Click(object sender, EventArgs e)
        {
            //if (mobjCurrentHostedApplication != null)
            //{
            //    CatalogSettings.HandleApplicationHostToolBarClick(mobjCurrentHostedApplication, this.mobjToolBarMain, (ToolBarButton)sender, e);
            //}
        }

        private void mobjMainMenu_MenuClick(object objSource, MenuItemEventArgs objArgs)
        {
            string strAction = objArgs.MenuItem.Tag as string;
            if (strAction != null)
            {
                if (strAction.StartsWith("Theme."))
                {
                    this.Context.CurrentTheme = strAction.Replace("Theme.", "");
                    return;
                }
                switch (strAction)
                {
                    case "PWD":
                        TVC.Modules.Com.frmChangePWD frm = new Modules.Com.frmChangePWD(this);
                        frm.Show();
                        break;
                    //case "Print":
                    //    MessageBox.Show(((Gizmox.WebGUI.Common.Interfaces.ISessionRegistry)this.Context.Session).Count.ToString());
                    //    break;
                    case "AboutVWG":
                        Forms.AboutVWGForm objAboutVWGForm = new TVC.Forms.AboutVWGForm();
                        objAboutVWGForm.ShowDialog();
                        break;
                    case "LOGOUT":
                        Context.Session.IsLoggedOn = false;
                        VWGContext.Current.HostContext.HttpContext.Session.Abandon();
                        break;
                    case "DDB":
                        SelectCategory("DDB", "");
                        break;
                    case "Paste":
                        //MessageBox.Show("Paste");
                        break;
                    default:
                        //MessageBox.Show(strAction);
                        break;
                }
            }
        }

        //private void mobjPoweredByPanel_Click(object sender, EventArgs e)
        //{

        //}

        public void SetMsg(string msg)
        {
            //MessageBox.Show(msg);

            this.sbpErr.Text = msg;
        }

        public void SetLogon(string str)
        {
            this.sbpLogon.Text = String.Format("{0} | {1} | Login : {2:dd/MM/yyyy hh:mm}", str, System.Net.Dns.GetHostName(), DateTime.Now);
        }

        private void mobjStatusBar_Click(object sender, EventArgs e)
        {
            Forms.frmMsg frm = new Forms.frmMsg();
            frm.ShowMsg(sbpErr.Text);
        }
        public bool ChangeScreen()
        {
            mobjMainMenu.Visible = !mobjMainMenu.Visible;
            //mobjCommandText.Visible = mobjMainMenu.Visible;
            mobjPanelCategories.Visible = mobjMainMenu.Visible;
            //mobjPanelRightSide.Visible = mobjMainMenu.Visible;
            //mobjPanelRightSide.Visible = mobjMainMenu.Visible & Next.Visible;
            return mobjMainMenu.Visible;
        }

        private void Next_Click(object sender, EventArgs e)
        {
            Next.Visible = false;
            Back.Visible = true;
            //mobjPanelRightSide.Visible = Next.Visible;
            //this.mobjPanelRightSide.Size = new System.Drawing.Size(1, 622);
        }

        private void Back_Click(object sender, EventArgs e)
        {
            Back.Visible = false;
            Next.Visible = true;
            //mobjPanelRightSide.Visible = Next.Visible;
            //this.mobjPanelRightSide.Size = new System.Drawing.Size(237, 622);

        }

        //private void BaseForm_Activated(object sender, EventArgs e)
        //{

        //}
        public virtual bool IsPermis(int id)
        {
            return true;
        }

        private void btnEsc_Click(object sender, EventArgs e)
        {

            //MainForm main = new MainForm();
            //main.ChangeScreen();
            mobjMainMenu.Visible = true;
            //mobjCommandText.Visible = mobjMainMenu.Visible;
            mobjPanelCategories.Visible = true;
        }

    }




}
